<HTML><HEAD><TITLE>free(?Var)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Type Testing</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>free(?Var)</H1>
Succeeds if Var is a free variable, not an attributed one.


<DL>
<DT><EM>Var</EM></DT>
<DD>Prolog term.
</DD>
</DL>
<H2>Description</H2>
   Used to test whether Var is a free variable.  free/1 is like var/1 but
   does not succeed for attributed variables.
<P>
   CAUTION: is it usually a mistake to distinguish between free and attributed
   variables, because variables can have several unrelated attributes (for
   example, some attributes are only for debugging purposes and should not
   affect the program behaviour at all). Correct code should check for the
   presence or absence of a particular attribute, and only use the free/1
   test as a shortcut for detecting the absence of any attribute, e.g.
<PRE>
    add_my_attribute_if_needed(X) :-
        free(X),
        % X has no attributes at all: add my one
        add_attribute(X, my_attribute).
    add_my_attribute_if_needed(X{my_attr:Attr}) ?-
        ( var(Attr) ->
            % X has attributes, but not my one: add it
            add_attribute(X, my_attribute)
        ;
            % X already has my attribute: do nothing
            true
        ).
</PRE>

<H3>Modes and Determinism</H3><UL>
<LI>free(?) is semidet
</UL>
<H3>Fail Conditions</H3>
Fails if Var is instantiated or an attributed variable
<H2>Examples</H2>
<PRE>
Success:
      free(X).
      free(_abc).
      free(_).

Fail:
      free(X{a}).
      suspend:(X&gt;0), free(X).
      var(atom).
      var('Abc').



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/typetest/nonground-1.html">nonground / 1</A>, <A HREF="../../kernel/typetest/nonvar-1.html">nonvar / 1</A>, <A HREF="../../kernel/typetest/meta-1.html">meta / 1</A>, <A HREF="../../kernel/typetest/type_of-2.html">type_of / 2</A>, <A HREF="../../kernel/typetest/var-1.html">var / 1</A>
</BODY></HTML>
